package com.wobangkj.common.service.impl;

import com.wobangkj.common.model.crud.Liked;
import com.wobangkj.common.repository.LikedRepository;
import com.wobangkj.common.service.LikedService;
import com.wobangkj.tool.api.result.Result;
import com.wobangkj.tool.util.sql.CrudUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class LikedServiceImpl implements LikedService {

    @Autowired
    private LikedRepository repository;

    @Override
    public Object delete(Long id) {
        return CrudUtil.delete(id, repository);
    }

    @Override
    public Object id(Long id) {
        return CrudUtil.getById(id, repository);
    }

    @Override
    @SuppressWarnings("Duplicates")
    public Object create(Liked liked) {
        try {
            Liked createData = repository.save(liked);
            // 使用 uuid 作为源 token
            //String     token = UUID.randomUUID().toString().replace("-", "");
            //TokenModel model = new TokenModel(createData.getId(), token);
            // 30 分钟有效期
            //cacheManager.set(model.getToken(), new CacheModel(TOKEN_MINUTE, model));
            return Result.GetMapData(Result.CodeCreate, Result.MsgCreate);//, model);
        } catch (Exception e) {
            return Result.GetMapData(Result.CodeSql, e.getCause().getCause().getMessage());
        }
    }

    @Override
    public List<Liked> findById(String likerId, String likedContentId, String likedClass) {
        return repository.findById(likerId,likedContentId,likedClass);
    }

    @Override
    public List<Map> findMy(String Id) {
        return repository.findMy(Id);
    }

    @Override
    public Long findLiked(String likerId, String likedContentId, String likedClass) {
        return repository.findLiked(likerId,likedContentId,likedClass);
    }


    @Transactional
    @Override
    public void updateShareNumById(Long id) {
        repository.updateShareNumById(id);
    }

    @Transactional
    @Override
    public void updateDynamicNumById(Long id) {
        repository.updateDynamicNumById(id);
    }

    @Transactional
    @Override
    public void updateCommentNumById(Long id) {
        repository.updateCommentNumById(id);
    }

    @Transactional
    @Override
    public void deleteShareNumById(Long id) {
        repository.deleteShareNumById(id);
    }

    @Transactional
    @Override
    public void deleteDynamicNumById(Long id) {
        repository.deleteDynamicNumById(id);
    }

    @Transactional
    @Override
    public void deleteCommentNumById(Long id) {
        repository.deleteCommentNumById(id);
    }

    @Override
    public String getSharerId(String ContentId) {
        return repository.getSharerId(ContentId);
    }

    @Override
    public String getDynamicPublisherId(String ContentId) {
        return repository.getDynamicPublisherId(ContentId);
    }

    @Override
    public String getCommentPublisherId(String ContentId) {
        return repository.getCommentPublisherId(ContentId);
    }


}
